home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 014 / termcap / tgetnum.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  2KB  |  106 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *            Copyright (c) 1982, Fred Fish            *
  4.  *                All Rights Reserved                *
  5.  *                                    *
  6.  *    This software and/or documentation is released for public    *
  7.  *    distribution for personal, non-commercial use only.        *
  8.  *    Limited rights to use, modify, and redistribute are hereby    *
  9.  *    granted for non-commercial purposes, provided that all        *
  10.  *    copyright notices remain intact and all changes are clearly    *
  11.  *    documented.  The author makes no warranty of any kind with    *
  12.  *    respect to this product and explicitly disclaims any implied    *
  13.  *    warranties of merchantability or fitness for any particular    *
  14.  *    purpose.                            *
  15.  *                                    *
  16.  ************************************************************************
  17.  */
  18.  
  19.  
  20. /*
  21.  *  LIBRARY FUNCTION
  22.  *
  23.  *    tgetnum   extract numeric option from termcap entry
  24.  *
  25.  *  KEY WORDS
  26.  *
  27.  *    termcap
  28.  *    ce functions
  29.  *
  30.  *  SYNOPSIS
  31.  *
  32.  *    tgetnum(id)
  33.  *    char *id;
  34.  *
  35.  *  DESCRIPTION
  36.  *
  37.  *    Returns numeric value of capability <id>, or -1 if <id>
  38.  *    is not found.   Knows about octal numbers, which
  39.  *    begin with 0.
  40.  *
  41.  */
  42.  
  43. #include <stdio.h>
  44.  
  45. extern char *_tcpbuf;        /* Termcap entry buffer pointer */
  46.  
  47. /*
  48.  *  PSEUDO CODE
  49.  *
  50.  *    Begin tgetnum
  51.  *        Initialize pointer to the termcap entry buffer.
  52.  *        While there is a field to process
  53.  *        Skip over the field separator character.
  54.  *        If this is the entry we want then
  55.  *            If the entry is not a numeric then
  56.  *            Return failure value.
  57.  *            Else
  58.  *            Initialize value to zero.
  59.  *            If number begins with zero then
  60.  *                Set accumulation base to 8.
  61.  *            Else
  62.  *                Set accumulation base to 10.
  63.  *            End if
  64.  *            While there is a numeric character
  65.  *                Accumulate the value.
  66.  *            End while
  67.  *            Return value.
  68.  *            End if
  69.  *        End if
  70.  *        End while
  71.  *        Return failure value.
  72.  *    End tgetnum
  73.  *
  74.  */
  75.  
  76. tgetnum(id)
  77. char *id;
  78. {
  79.     int value, base;
  80.     char *bp;
  81.     extern char *index();
  82.  
  83.     bp = _tcpbuf;
  84.     while ((bp = index(bp,':')) != NULL) {
  85.     bp++;
  86.     if (*bp++ == id[0] && *bp != NULL && *bp++ == id[1]) {
  87.         if (*bp != NULL && *bp++ != '#') {
  88.         return(-1);
  89.         } else {
  90.         value = 0;
  91.         if (*bp == '0') {
  92.             base = 8;
  93.         } else {
  94.             base = 10;
  95.         }
  96.         while (isdigit(*bp)) {
  97.             value *= base;
  98.             value += (*bp++ - '0');
  99.         }
  100.         return(value);
  101.         }
  102.     }
  103.     }
  104.     return(-1);
  105. }
  106.